<?php

namespace Music\ApiBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var string
     *
     * @ORM\Column(name="ip", type="string", length=255, nullable=true)
     */
    protected $ip;
    
    
    protected $ips = array(
        '192.168.180.157'   => 'Aveltsov',
        '192.168.180.15'    => 'Shiryaev',
        '192.168.180.40'    => 'Andreev',
        '192.168.180.54'    => 'Kochetkov',
        '192.168.180.122'   => 'Sviatchenko',
        '192.168.180.121'   => 'Sviatchenko',
        '192.168.180.47'    => 'Pak',
        '192.168.180.202'   => 'Eleseev',
        '192.168.180.37'    => 'Pelihov',
        '192.168.180.103'   => 'Levin',
        '127.0.0.1'         => 'Levin',
        '192.168.180.129'   => 'Voronina',
        '192.168.180.66'    => 'Faruh'
    );
    
    public function __construct()
    {
        parent::__construct();
        // your own logic
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set ip
     *
     * @param string $ip
     * @return User
     */
    public function setIp($ip)
    {
        $this->ip = $ip;

        return $this;
    }

    /**
     * Get ip
     *
     * @return string 
     */
    public function getIp()
    {
        return $this->ip;
    }
    
    public function setUsername($username) {
        $this->setIp($_SERVER['REMOTE_ADDR']);
        parent::setUsername($username);
    }
    
    public function getAddBy(){
        return isset($this->ips[$this->getIp()])? $this->ips[$this->getIp()] : false;
    }
}
